<template>
  <!-- 添加或修改核销明细信息管理对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-tab-pane label="基本信息" name="first">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="核销总金额" prop="pinMoney">
                <el-input-number :precision="2" v-model="form.pinMoney" :min="0" placeholder="请输入核销金额"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="核销日期" prop="pinDate">
                <el-date-picker clearable
                                v-model="form.pinDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择核销日期">
                </el-date-picker>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="核销记录" prop="files">
                <file-upload v-model="form.files"/>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注" prop="remark">
                <el-input type="textarea" v-model="form.remark" placeholder="请输入备注"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {addAction, getById, updateAction} from '@/api/manage';
import moment from 'moment';

export default {
  name: "GoodsInvoiceHxallForm",
  data() {
    return {
      // 遮罩层
      loading: true,
      activeName: "first",
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {
        ids: "",
      },
      // 表单校验
      rules: {
        pinMoney: [
          {required: true, message: "核销总金额不能为空", trigger: "blur"}
        ],
      },
      url: {
        getById: '/goodsInvoiceDetail/goodsInvoiceDetail/',
        addPiliang: '/goodsInvoiceDetail/goodsInvoiceDetail/addPiliang',
        edit: '/goodsInvoiceDetail/goodsInvoiceDetail/edit',
        getAllMoney: '/goodsInvoice/goodsInvoice/getAllMoney/',
      },
    };
  },
  created() {
  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        invoiceId: null,
        pinMoney: null,
        pinDate: new Date,
        files: null,
        saleName: null,
        status: "0",
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 新增按钮操作 */
    hexiaoAll(ids) {
      this.reset();
      this.open = true;
      this.form.ids = ids;
      this.allMoney(ids);
    },
    allMoney(ids) {
      getById(this.url.getAllMoney, ids).then(response => {
        this.form.pinMoney = response.data;
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getById(this.url.getById, id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改核销明细信息管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAction(this.url.edit, this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.$emit('ok');
            });
          } else {
            addAction(this.url.addPiliang, this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.$emit('ok');
            });
          }
        }
      });
    },
  }
};
</script>
